<?php

/**
 * WeEngine System
 *
 * (c) We7Team 2021 <https://www.w7.cc>
 *
 * This is not a free software
 * Using it under the license terms
 * visited https://www.w7.cc for more details
 */

namespace W7\Addons\demo_engine_wechat\Controller;

use W7\App\Controller\BaseController;
use W7\Http\Message\Server\Request;
use W7\Addons\demo_engine_wechat\Model\Entity\News;
use W7\Addons\demo_engine_wechat\Model\Logic\NewsLogic;

class TestController extends BaseController
{
    public function test()
    {
        $list = NewsLogic::instance()->lists();
        return $this->render('@demo_engine_wechat/test/test', ['list' => $list]);
    }

    public function admindetail(Request $request)
    {
        $validatedData = $this->validate($request, [
            'id' => 'required|numeric',
        ]);
        $newsInfo = News::query()->where('id', $validatedData['id'])->first();
        if (empty($newsInfo)) {
            throw new LogicErrorException('文章不存在！');
        }
        return $this->render('@demo_engine_wechat/test/admindetail', ['info' => $newsInfo]);
    }
}
